<template>
	<view style="height: 100%">
		<view v-if="info">
			<ul class="db bgcf pd015 mt10">
				<li class="df ac sb h48 bbf1">
					<span class="f14 cf5">*</span>
					<p class="f14 c28">企业名称</p>
					<view class="tr f1 ml15 f14 c28">{{ val[0] }}</view>
				</li>
				<view class="search-D" v-if="SySeach==true">
					<view @click="SySeach=false" v-if="Result" class="" style="padding: 6px 0 6px 6px;"> 关闭 </view>
					<view v-for="(item,index) in Result" :key="index" class="">
						<view class="titleName" @click="selectName(item.Name)">
							{{item.Name}}
						</view>
					</view>
				</view>
				<li class="df ac sb h48 bbf1">
					<span class="f14 cf5">*</span>
					<p class="f14 c28">联系人</p>
					<view class="tr f1 ml15 f14 c28">{{ val[1] }}</view>
				</li>
				<li class="df ac sb h48 bbf1">
					<span class="f14 cf5">*</span>
					<p class="f14 c28">联系方式</p>
					<view class="tr f1 ml15 f14 c28">{{ val[2] }}</view>
				</li>
				<li class="df ac sb h48 bbf1">
					<span class="f14 cf5">*</span>
					<p class="f14 c28">职位</p>
					<view class="tr f1 ml15 f14 c28">{{ val[3] }}</view>
				</li>
				<li class="df ac sb h48 bbf1">
					<span class="f14 cf5"></span>
					<p class="f14 c28">
						<image style="width:60rpx;max-height:49rpx" :src="getImgSrc('/uploads/20241125/17325049426743ed6eaae34.jpg')" mode="widthFix"/>
					</p>
					<view class="tr f1 ml15 f14 c28">{{ val[4] ? val[4] : '' }}</view>
				</li>
			</ul>
			<view class="pd015">
				<view class="mt15 df ac">
					资料文件
				</view>
				<ul class="df ac fw mt15" v-if="info.drawing.length != 0">
					<block v-for="(it, index) in info.drawing" :key="index">
						<li class="mb8 mr8 img64 pr db">
							<image class="img64" referrerPolicy='no-referrer' :src="getImgSrc(it)" mode="aspectFill" />
						</li>
					</block>
				</ul>
				<view class="h44 mt8 bgcf7 df ac pd015" v-if="info.file.length != 0"
					v-for="(it, index) in info.file" :key="index">
					<image class="img16" src="https://wx.xtwaixie.com/img/file.png"></image>
					<view class="ml8 f14 c28 f1">{{ it.name }}</view>
					<view class="f12 c10" style="width:100rpx;" @click="onLook(index)">在线预览</view>
				</view>
			</view>
			<view>
				
			</view>
			<!-- <view style="height:180rpx;" v-if="drawing.length != 0 || file_name.length != 0"></view> -->
			<view class="pd15 bgcf mt15">
				<button class="sub" @tap="onSub">编辑</button>
			</view>
		</view>
	</view>
</template>

<script>
	import http from '../../utils/http';
	export default {
		data() {
			return {
				val: ['', '', '', '','',''],
				is_check:true,
				drawing:[],
				file_name:[],
				file:[],
				is_examine:false,
				info:null,
				cg_status:0
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad(options) {
			const token = uni.getStorageSync('token')
			if(token){
				this.getUserInfo()
			}
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady() {},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow() {},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom() {},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage() {},
		methods: {
			onLook(index){
				let url = this.info.file[index].url;
				// const status = this.changeBtn(url)
				const extension = this.getFileExtension(url);
				const randfile = this.info.file[index].name.endsWith('.' + extension) ? this.info.file[index].name : this.info.file[index].name + '.' + extension
				const newPath = `${wx.env.USER_DATA_PATH}/${randfile}`;
				let showMenu = this.info.grade == 2;
				uni.showLoading({
					title: '文件下载中'
				});
				uni.downloadFile({
					url: this.getImgSrc(url),
					filePath: newPath,
					success(res) {
						console.log(res);
						if (res.statusCode === 200) {
							uni.openDocument({
								filePath: res.filePath || res.tempFilePath,
								showMenu: true,
								success(res) {
									// console.log(res);
									console.log('打开/文档成功');
									uni.hideLoading();
								},
								fail(res) {
									console.log(res);
									uni.hideLoading();
								}
							});
						} else {
							uni.hideLoading();
						}
					},
					fail(res) {
						console.log(res);
						uni.hideLoading();
					}
				});
			},
			getFileExtension(filePath) {
				// 使用最后一个点和文件名的分隔符来获取文件名
				const filename = filePath.split('/').pop();
				// 获取文件名中的后缀部分
				const extension = filename.split('.').pop();
				return extension;
			},
			getUserInfo(){
				http.request('user/userInfo').then(res=>{
					this.info = res.data.userInfo
					this.info.drawing = JSON.parse(this.info.drawing)
					this.info.file = JSON.parse(this.info.file)
					this.is_examine = this.info.cg_status === 1
					this.cg_status = this.info.cg_status
					this.setData({
						[`val[0]`]: res.data.userInfo.company,
						[`val[1]`]: res.data.userInfo.username,
						[`val[2]`]: res.data.userInfo.company_tel,
						[`val[3]`]: res.data.userInfo.job,
						[`val[4]`]: res.data.userInfo.wexin,
					});
				})
			},
			onBack() {
				uni.redirectTo({
					url: "/pages/my/my"
				})
			},
			onChange(e){
				this.is_check = e.detail
			},
			onSub() {
				uni.navigateTo({
					url:'/pages/my/editInfo'
				})
			},
		}
	};
</script>
<style>
	@import '@/pages/my/editInfo.css';
</style>